package cn.zhaoyuening.schoolmates.web.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.zhaoyuening.schoolmates.domain.SchoolmatesCategory;
import cn.zhaoyuening.schoolmates.service.SchoolmatesCategoryService;
import cn.zhaoyuening.schoolmates.utils.JsonUtils;
import cn.zhaoyuening.schoolmates.utils.ResponceResult;

@RestController
@RequestMapping("admin")
public class AdminSchoolmateCategoryController {
	@Autowired
	private SchoolmatesCategoryService schoolmatesCategoryService;
	
	@RequestMapping(value ="schoolmatesCategory",method=RequestMethod.POST)
	public String add(String name){
		schoolmatesCategoryService.addOrEdit(new SchoolmatesCategory(name));
		return JsonUtils.objectToJson(ResponceResult.ok());
	}
	
	@RequestMapping(value="schoolmatesCategory",method=RequestMethod.DELETE)
	public String delete(Long id){
		SchoolmatesCategory schoolmatesCategory = new SchoolmatesCategory();
		schoolmatesCategory.setId(id);
		schoolmatesCategoryService.delete(schoolmatesCategory);
		return JsonUtils.objectToJson(ResponceResult.ok());
	}
	
	@RequestMapping(value ="schoolmatesCategory",method=RequestMethod.PUT)
	public String update(Long id,String name){
		schoolmatesCategoryService.addOrEdit(new SchoolmatesCategory(id,name));
		return JsonUtils.objectToJson(ResponceResult.ok());
	}
}
